package com.zuxia.action;

import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.zuxia.entity.Repair;
import com.zuxia.service.IRepairService;
import com.zuxia.uilt.PageModel;

@Controller()
@Scope("prototype")
@ParentPackage("struts-default")
@Namespace("/")
@Results({ 
	@Result(name = "selectRepair", type = "dispatcher", location = "/admin/chaRepair.jsp"), 
	@Result(name = "empty", type = "dispatcher", location = "/admin/empty.jsp"),
	@Result(name = "fsrep", type = "dispatcher", location = "/admin/addRepair.jsp"),
	@Result(name = "Y", type = "redirectAction", location = "/findRepair")
	
})
public class RepairAction extends ActionSupport implements ModelDriven<Repair>{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Repair repair = new Repair();
	
	@Override
	public Repair getModel() {
		// TODO Auto-generated method stub
		return repair;
	}
	
	@Autowired
	private IRepairService repservice;
	private int pageNo = 1;// ��̬�ı� ҳ��ȡ��
	private int pageSize = 5;// �̶�����
	private String xname="";
	private PageModel<?> pm ;
	

	public int getPageNo() {
		return pageNo;
	}
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}
	public PageModel<?> getPm() {
		return pm;
	}
	public void setPm(PageModel<?> pm) {
		this.pm = pm;
	}
	public Repair getRepair() {
		return repair;
	}
	public void setRepair(Repair repair) {
		this.repair = repair;
	}
	public IRepairService getRepservice() {
		return repservice;
	}
	public void setRepservice(IRepairService repservice) {
		this.repservice = repservice;
	}
	public String getXname() {
		return xname;
	}
	public void setXname(String xname) {
		this.xname = xname;
	}
	
	@Action("findRepair")//��ѯά�޼�¼
	public String findRepair(){
		pm = new PageModel();
		List list = repservice.findRepair(pageNo,xname,pageSize);
		if(list.size()> 0){
			pm.setList(list);
			pm.setCount(repservice.repsize());
			pm.setPageNo(pageNo);
			pm.setPageSize(5);
			ActionContext.getContext().put("rep", pm);
			int sumPage = pm.getSumPage();
			
			ActionContext.getContext().put("sumPage", sumPage);
			return "selectRepair";
		}
		return "empty";
	}
	//ɾ��
	@Action("deleteRepair")
	public String deleteRepair() {
		repservice.delrep(repair);
		
		return "Y";
	}
	
	@Action("addRepair")
	public String addRepair() {
		repservice.addrep(repair);
		return "Y";
	}
	
	@Action("findupdateRepair")
	public String findupdateRepair() {
		repair = repservice.findupdateRepair(repair);
		return "fsrep";
	}
	
	@Action("updateRepair")
	public String updateRepair() {
		repservice.updrep(repair);
		return "Y";
	}
	
}
